package com.gitee.wsl.transform.split

import com.gitee.wsl.transform.converter.case.CaseFormat
import com.gitee.wsl.transform.converter.case.universalWordSplitter

/**
 * An interface that defines a word splitter that can be used to split a string into multiple words.
 */
fun interface WordSplitter {
    /**
     * Splits [string] into multiple words and returns a list of them.
     */
    fun splitToWords(string: String): List<String>

    companion object
}

/**
 * Splits this string into multiple words using [specified][splitter] [WordSplitter] and returns a list of words.
 */
fun String.splitToWords(splitter: WordSplitter = universalWordSplitter()) = splitter.splitToWords(this)

/**
 * Splits this string into multiple words using [WordSplitterConfigurable] configured with [config] and returns a list of words.
 */
fun String.splitToWords(config: WordSplitterConfig) = splitToWords(WordSplitterConfigurable(config))

fun String.splitToWords(caseFormat: CaseFormat) = caseFormat.splitToWords(this)

